package com.kaxicore.kaxi.mapper;

import com.kaxicore.kaxi.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

// 写代码的顺序从底层代码写起
// 利用这个注解让mybatis自动加载
@Mapper
public interface UserMapper {

    // 增删改查
    // 查数据
    @Select("SELECT * FROM tb_user")
    public List<User> geTestUsers() throws Exception;

    // 改数据
    public void updateTestUser(User user) throws Exception;

    // 新增用户
    @Insert("INSERT INTO tb_user(user_name, password) VALUES(#{userName}, #{password})")
    public void addTestUser(User user) throws Exception;

    // 根据id删除
    public void deleteTestUser(int id) throws Exception;

    // 查看是否有重名用户
    @Select("SELECT * FROM tb_user WHERE user_name=#{name} LIMIT 1")
    public User getUserByName(String name) throws Exception;

}
